#!  python
# -*- coding: UTF-8 -*-
'''
@Author ：Star
@Date ：2022/11/26  
'''

import requests
import time

global s

def login():
    s = requests.Session()
    url = "http://118.121.200.162:8085/loginCheck.do"
    mydata = {
        "userID":"star",
        "password":"123456"
    }
    res = s.post(url, data=mydata)
    assert res.status_code == 200
    return s

s = login()

# 查询全部留言列表
def MessageList():
    # s = login()
    url = "http://118.121.200.162:8085/message/getMessageList"
    p = {
        "page":1
    }
    res = s.get(url,params=p)
    assert res.status_code == 200
    assert "场馆怎么预约" in res.text

# 发布留言
def sendmessage():
    # s = login()
    url = "http://118.121.200.162:8085/sendMessage"
    now = time.strftime("%Y%m%d%H%M%S", time.localtime())
    con = "卓星的留言" + now
    mycontent = {
        "userID":"star",
        "content":con
    }
    res = s.post(url, data=mycontent)
    # print(res.text)
    assert res.status_code == 200
    assert "发布成功" in res.text
    return con

# 我的留言
def findUesr():
    url = "http://118.121.200.162:8085/message/findUserList"
    p = {
        "page": 1
    }
    send = sendmessage()
    res = s.get(url, params=p)
    assert res.status_code == 200
    assert send in res.text
    allMess = res.json()
    for i in allMess:
        if i.get("content") in send:
            return i.get("messageID")


def delMessage():
    messID = findUesr()
    print(messID)
    url = "http://118.121.200.162:8085/delMessage.do"
    data = {
        "messageID":messID
    }
    res = s.post(url,data=data)
    assert res.status_code == 200
    assert res.text == "true"


MessageList()
delMessage()
